package com.ruoyi.teach.service.impl;

import java.util.List;

import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.teach.mapper.TeachPlanContentMapper;
import com.ruoyi.teach.domain.TeachPlanContent;
import com.ruoyi.teach.service.ITeachPlanContentService;

/**
 * 教案内容Service业务层处理
 * 
 * @author yepanpan
 * @date 2021-03-15
 */
@Service
public class TeachPlanContentServiceImpl implements ITeachPlanContentService 
{
    @Autowired
    private TeachPlanContentMapper teachPlanContentMapper;

    /**
     * 查询教案内容
     * 
     * @param id 教案内容ID
     * @return 教案内容
     */
    @Override
    public TeachPlanContent selectTeachPlanContentById(Long id)
    {
        return teachPlanContentMapper.selectTeachPlanContentById(id);
    }

    /**
     * 查询教案内容列表
     * 
     * @param teachPlanContent 教案内容
     * @return 教案内容
     */
    @Override
    public List<TeachPlanContent> selectTeachPlanContentList(TeachPlanContent teachPlanContent)
    {
        return teachPlanContentMapper.selectTeachPlanContentList(teachPlanContent);
    }

    /**
     * 新增教案内容
     * 
     * @param teachPlanContent 教案内容
     * @return 结果
     */
    @Override
    public int insertTeachPlanContent(TeachPlanContent teachPlanContent)
    {
    	TeachPlanContent pcc = new TeachPlanContent();
    	pcc.setPlanId(teachPlanContent.getPlanId());
    	pcc.setPeriod(teachPlanContent.getPeriod());
    	List<TeachPlanContent> list = teachPlanContentMapper.selectTeachPlanContentList(pcc);
    	if(list != null && list.size() > 0) {
    		throw new CustomException("课时不能重复");
    	}
        teachPlanContent.setCreateTime(DateUtils.getNowDate());
        teachPlanContent.setCreateBy(SecurityUtils.getUsername());
        return teachPlanContentMapper.insertTeachPlanContent(teachPlanContent);
    }

    /**
     * 修改教案内容
     * 
     * @param teachPlanContent 教案内容
     * @return 结果
     */
    @Override
    public int updateTeachPlanContent(TeachPlanContent teachPlanContent)
    {
        teachPlanContent.setUpdateTime(DateUtils.getNowDate());
        teachPlanContent.setUpdateBy(SecurityUtils.getUsername());
        return teachPlanContentMapper.updateTeachPlanContent(teachPlanContent);
    }

    /**
     * 批量删除教案内容
     * 
     * @param ids 需要删除的教案内容ID
     * @return 结果
     */
    @Override
    public int deleteTeachPlanContentByIds(Long[] ids)
    {
        return teachPlanContentMapper.deleteTeachPlanContentByIds(ids);
    }

    /**
     * 删除教案内容信息
     * 
     * @param id 教案内容ID
     * @return 结果
     */
    @Override
    public int deleteTeachPlanContentById(Long id)
    {
        return teachPlanContentMapper.deleteTeachPlanContentById(id);
    }
}
